﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TheHeGeoCommercial.Admin
{
    public partial class Login : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
             Session["CURRENT_USER"] = null;

            if (string.IsNullOrEmpty(txtUserName.Text)||string.IsNullOrEmpty(txtPassWord.Text))
                return;
            string pwd = UserPwdEncrypt(txtPassWord.Text);
            using (var ent = new Dao.TheheGeoCommercialEntities())
            {
                var us =
                    (from u in ent.Users where (u.UserName == txtUserName.Text && u.PassWord == pwd) select u)
                        .FirstOrDefault();
                if (us == null)
                {
                    lblNotice.Visible = true;
                }
                else
                {
                    lblNotice.Visible = false;
                    Session["CURRENT_USER"] = txtUserName.Text;
                    Response.Redirect("~/Admin/AddProduct.aspx");
                }
            }
        }
        protected string UserPwdEncrypt(string pwd)
        {
            return pwd;
        }
    }
}